package br.com.aquinoevasconcelos.servlets.orcamento;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.aquinoevasconcelos.excecao.EmailException;
import br.com.aquinoevasconcelos.fachada.Fachada;

/**
 * Servlet implementation class ResponderOrcamento
 */
@WebServlet("/ResponderOrcamento")
public class ResponderOrcamento extends HttpServlet {
	private static final long serialVersionUID = 1L;
 
	
    public ResponderOrcamento() {
        super();

    }
    
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	
		Fachada fachada = Fachada.getInstancia();


    	
		String nome = request.getParameter("nome");
		String emailDestinatario = request.getParameter("email");
		String msgResposta = request.getParameter("resposta");

		
		try {
			
			fachada.RespostaOrcamento(nome, msgResposta, emailDestinatario);
			response.sendRedirect("ListaOrcamento");
		
		} catch (EmailException e) {
			
			RequestDispatcher rd = request
					.getRequestDispatcher("../erro.jsp");
			rd.forward(request, response);
			e.printStackTrace();
		}
		
	}
    

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

}
